<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateBuyTable extends Migration
{
  /**
   * Run the migrations.
   *
   * @return void
   */
  public function up()
  {
    Schema::create('buy', function (Blueprint $table) {
      $table->string('id')->primary();
      $table->string('transaction_id')->unique()->nullable()->comment('商户流水号');
      $table->foreignId('seller_id');
      $table->foreignId('member_id')->nullable();
      $table->foreignId('agent_id')->nullable();
      $table->string('bank')->comment('银行');
      $table->string('bankcard')->comment('银行卡号');
      $table->string('realname')->comment('姓名');
      // $table->unsignedDecimal('money')->nullable();
      $table->unsignedDecimal('coins', 16, 3);
      $table->unsignedDecimal('fee', 8, 3)->nullable();
      $table->unsignedDecimal('agent_fee', 8, 3)->nullable();
      $table->unsignedDecimal('seller_fee', 8, 3)->nullable();
      $table->unsignedDecimal('tip')->nullable();
      $table->unsignedDecimal('agent_tip')->nullable();
      $table->unsignedDecimal('seller_tip')->nullable();
      $table->unsignedDecimal('deposit', 8, 3)->nullable();
      $table->unsignedDecimal('agent_tip_fee', 8, 3)->nullable();
      $table->enum('state', ['waiting', 'took', 'frozen', 'unfreeze', 'fail'])->default('waiting');
      // $table->string('callback_url')->nullable()->comment('订单完成回调地址');
      $table->unsignedTinyInteger('callback_num')->default(0)->comment('订单完成回调次数');
      $table->unsignedTinyInteger('callback_ok')->default(0)->comment('回调收到回复OK？1：收到');
      $table->text('callback_content')->nullable()->comment('订单完成回调内容');
      $table->timestamp('took_at')->nullable();
      // $table->timestamp('frozen_at')->nullable();
      $table->timestamp('freeze_at')->nullable();
      $table->timestamp('unfreeze_at')->nullable();
      // $table->timestamp('done_at')->nullable();
      $table->timestamps();
    });
  }

  /**
   * Reverse the migrations.
   *
   * @return void
   */
  public function down()
  {
    Schema::dropIfExists('buy');
  }
}
